﻿/******************************************************************************
* File description: BoxChromatogramCollectSettings.qml
* Function: 能谱图设置（已弃用）
* Current Version: 1.0.0
* Author: JNN
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.0
import QtQuick.Window 2.12
import "../components"

Window {
    id: root
    height: 430*dp
    width: 500*dp
    minimumHeight: 430*dp
    maximumHeight: 430*dp
    minimumWidth: 500*dp
    maximumWidth: 500*dp

    title: "配置"

    signal accepted()
    signal rejected()

    onHeightChanged: {
        root.height = 430*dp
        root.width = 500*dp
    }

    // 从后端获取数据并显示
    function state2edit(){
//        var res = CChromManager.getDetectMode()
//        tabButton_isauto.index = res["IsAuto"]
//        switchButton_autotype.checked = res["AutoType"]
//        edit_threshold.setText(res["Threshold"])
//        edit_startDelay.setText(res["DelayTimeCollect"])
//        edit_closeDelay.setText(res["DelayTimeStop"])
//        edit_durationTime.setText(res["TimeCollect"])
    }
    // 将当前设置保存到后端
    function edit2state(){
//        CChromManager.setDetectMode(tabButton_isauto.index, switchButton_autotype.checked, edit_threshold.getText(), edit_startDelay.getText(), edit_durationTime.getText(), edit_closeDelay.getText())
    }

    property bool isAuto: tabButton_isauto.index === 0
    property int  autoType: switchButton_autotype.checked

    onVisibleChanged: {
        if(visible){
            state2edit()
        }
    }

    Rectangle{
        id: layout_top
        x: 10*dp; width: parent.width - 2*x
        y: 10*dp; height: 300*dp

        border.color: "#CCCCCC"

        Column{
            width: parent.width
            spacing: isAuto ? 15*dp : 25*dp
            CustomTabButton{
                id: tabButton_isauto
                model: ["自动", "手动"]
                direct: 0
                topPadding: 1; leftPadding: 1
                buttonH: 50*dp
                buttonW: 120*dp
                button_color_select: "white"
                borderline_posi: 1
                borderline_color_select: "#1677FF"
                button_color: "transparent"
                button_radius: 0
                color: "#F8F8F8"
                border.color: "#CCCCCC"
                width: parent.width
            }
            CustomSwitchButtonText{
                id: switchButton_autotype
                visible: isAuto
                width: 240*dp; height: 40*dp
                anchors.horizontalCenter: parent.horizontalCenter
                text0: "阈值"
                text1: "峰值"
                borderColor: "#AAAAAA"
                backgroundColor: "white"
                backgroundColor_checked: "#F5A61C"
                textColor: "#333333"
                textColor_checked: "white"
            }
            Item{
                height: 70*dp; width: parent.width
                CustomInputText{
                    id: edit_threshold
                    visible: isAuto
                    titleDirect: 1
                    title: autoType===0 ? "阈值" : "峰值"
                    x: parent.width * 0.5 - width - 10*dp
                    intflag: true
                }
                CustomInputText{
                    id: edit_startDelay
                    titleDirect: 1
                    title: "开始延迟时间(s)"
                    x: edit_threshold.visible ? parent.width * 0.5 + 10*dp : parent.width * 0.5 - width - 10*dp
                }
            }
            Item{
                height: 70*dp; width: parent.width
                CustomInputText{
                    id: edit_durationTime
                    titleDirect: 1
                    title: "产物接收时间(s)"
                    x: parent.width * 0.5 - width - 10*dp
                }
                CustomInputText{
                    id: edit_closeDelay
                    titleDirect: 1
                    title: "关闭检测延迟时间(s)"
                    x: parent.width * 0.5 + 10*dp
                }
            }
        }

        Item{
            id: layout_button
            y: layout_top.y + layout_top.height + 18*dp
            height: 40*dp; width: parent.width
            CustomButton{
                title: "取消"
                defaultMode2: true
                x: parent.width * 0.5 - width - 10*dp
                onClicked: {
                    root.close()
                    root.rejected()
                }
            }
            CustomButton{
                title: "确定"
                defaultMode1: true
                x: parent.width * 0.5 + 10*dp
                onClicked: {
                    posiThr = Number(edit_threshold.getText())
                    posiThr = Math.max(Math.min(posiThr, chart.maxY), 0)
                    changeType = isAuto ? 0 : 1
                    edit2state()
                    root.close()
                    root.accepted()
                }
            }
        }
    }

}
